package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AcCustodialUnit;
import com.ruoyi.system.service.IAcCustodialUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资产看管单元Controller
 *
 * @author ruoyi
 * @date 2025-04-07
 */
@RestController
@RequestMapping("/system/unit")
public class AcCustodialUnitController extends BaseController
{
    @Autowired
    private IAcCustodialUnitService acCustodialUnitService;

    /**
     * 查询资产看管单元列表
     */
    @PreAuthorize("@ss.hasPermi('system:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(AcCustodialUnit acCustodialUnit)
    {
        startPage();
        List<AcCustodialUnit> list = acCustodialUnitService.selectAcCustodialUnitList(acCustodialUnit);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:unit:list')")
    @GetMapping("/listNoPage")
    public TableDataInfo listNoPage(AcCustodialUnit acCustodialUnit)
    {
//        startPage();
        List<AcCustodialUnit> list = acCustodialUnitService.selectAcCustodialUnitList(acCustodialUnit);
        return getDataTable(list);
    }
    /**
     * 导出资产看管单元列表
     */
    @PreAuthorize("@ss.hasPermi('system:unit:export')")
    @Log(title = "资产看管单元", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AcCustodialUnit acCustodialUnit)
    {
        List<AcCustodialUnit> list = acCustodialUnitService.selectAcCustodialUnitList(acCustodialUnit);
        ExcelUtil<AcCustodialUnit> util = new ExcelUtil<AcCustodialUnit>(AcCustodialUnit.class);
        util.exportExcel(response, list, "资产看管单元数据");
    }

    /**
     * 获取资产看管单元详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:unit:query')")
    @GetMapping(value = "/{unitId}")
    public AjaxResult getInfo(@PathVariable("unitId") String unitId)
    {
        return success(acCustodialUnitService.selectAcCustodialUnitByUnitId(unitId));
    }

    /**
     * 新增资产看管单元
     */
    @PreAuthorize("@ss.hasPermi('system:unit:add')")
    @Log(title = "资产看管单元", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AcCustodialUnit acCustodialUnit)
    {
        return toAjax(acCustodialUnitService.insertAcCustodialUnit(acCustodialUnit));
    }

    /**
     * 修改资产看管单元
     */
    @PreAuthorize("@ss.hasPermi('system:unit:edit')")
    @Log(title = "资产看管单元", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AcCustodialUnit acCustodialUnit)
    {
        return toAjax(acCustodialUnitService.updateAcCustodialUnit(acCustodialUnit));
    }

    /**
     * 删除资产看管单元
     */
    @PreAuthorize("@ss.hasPermi('system:unit:remove')")
    @Log(title = "资产看管单元", businessType = BusinessType.DELETE)
	@DeleteMapping("/{unitIds}")
    public AjaxResult remove(@PathVariable String[] unitIds)
    {
        return toAjax(acCustodialUnitService.deleteAcCustodialUnitByUnitIds(unitIds));
    }
}
